﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Logging;

namespace JXPlatform.Infrastructure.Models
{
    [Export(typeof(ILoggerFacade))]
    public class CallbackLogger : ILoggerFacade
    {
        private readonly Queue<Tuple<string, Category, Priority>> _savedLogs = new Queue<Tuple<string, Category, Priority>>();
        public Action<string, Category, Priority> Callback { get; set; }

        public void Log(string message, Category category, Priority priority)
        {
            if (Callback != null)
            {
                Callback(message, category, priority);
            }
            else
            {
                _savedLogs.Enqueue(new Tuple<string, Category, Priority>(message, category, priority));
            }
        }
    }
}
